Menu

Overview

Relevant source files

Nacos is a dynamic service discovery, configuration management, and service management platform designed to help build, deliver, and manage microservices. Developed by Alibaba, Nacos provides essential infrastructure for efficiently managing cloud-native applications across private, hybrid, and public cloud environments.

This document provides an introduction to the Nacos codebase, its architecture, core components, and key functionalities. For more detailed information about specific components, refer to the respective wiki pages for Architecture and Module Structure.

What is Nacos?

Nacos (Naming and Configuration Service) is an open-source platform that addresses critical infrastructure needs for microservices architecture:

  1. Dynamic Service Discovery: Enables services to register themselves and discover other services via DNS or HTTP interfaces, including health checking to prevent routing to unhealthy instances.

  2. Dynamic Configuration Management: Centralizes configuration management across environments, eliminating the need for redeployment when configurations change.

  3. Dynamic DNS Service: Supports weighted routing, load balancing, and DNS-based service discovery within data centers.

  4. Service and Metadata Management: Provides a dashboard for service metadata and configuration management.

Sources: README.md12-35

System Architecture

Nacos implements a client-server architecture that supports both configuration management and service discovery functions.

Key Components

  1. Client SDK:

    • Provides client libraries for applications to interact with Nacos
    • Includes dedicated clients for both configuration and naming services
  2. Server Components:

    • Config Service: Manages configuration distribution and updates
    • Naming Service: Handles service registration, discovery, and health checking
    • Persistence Layer: Stores configurations and service information
    • Consistency Protocol: Ensures data consistency across cluster nodes using JRaft
  3. Web Console UI:

    • Administrative interface for managing configurations, services, and cluster

Sources: pom.xml601-624 client/pom.xml28-34 config/pom.xml28-34 naming/pom.xml30-34 console/pom.xml26-29

Module Structure

The Nacos codebase is organized into the following key modules:

Module Descriptions

ModuleDescription
nacos-apiCore APIs and interfaces including gRPC definitions
nacos-clientClient SDK for applications to interact with Nacos
nacos-commonCommon utilities and helper classes
nacos-coreCore framework functionality and cluster management
nacos-configConfiguration service implementation
nacos-namingService discovery and naming service implementation
nacos-consoleWeb UI and administrative console
nacos-consistencyData consistency mechanisms using JRaft
nacos-authAuthentication and authorization
nacos-persistenceData persistence and storage
nacos-pluginExtensibility points and plugin architecture

Sources: pom.xml601-624 client/pom.xml28-34 core/pom.xml30-34 config/pom.xml28-34 naming/pom.xml30-34 common/pom.xml29-34

Configuration Service

The configuration service manages application configurations centrally, allowing for dynamic updates without service restarts.

Key features:

  • Long polling for configuration changes
  • Local caching for performance
  • Configuration versioning
  • Multi-tenancy support with namespace
  • Support for different data formats (properties, JSON, XML, YAML, etc.)
  • Configuration change history tracking

Sources: config/pom.xml28-34

Service Discovery

The naming service enables dynamic service registration, discovery, and health checking.

Key features:

  • Service registration and de-registration
  • Service discovery
  • Health checking
  • Metadata management
  • Service clustering and grouping
  • Load balancing support
  • DNS-based service discovery

Sources: naming/pom.xml30-34

Authentication and Security

Nacos provides authentication and authorization capabilities:

Key security features:

  • JWT-based authentication
  • Role-based access control
  • Token management
  • Resource-level permissions
  • Plugin-based security architecture for extensibility

Sources: plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java48-161 auth/src/main/java/com/alibaba/nacos/auth/config/AuthErrorCode.java24-51

Data Persistence

Nacos provides flexible data persistence options:

Key persistence features:

  • Embedded storage for standalone mode
  • External database support for cluster mode
  • Database abstraction layer for multiple database types
  • Transactions support
  • Data migration capabilities

Sources: plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/AbstractMapper.java30-148 plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java30-93

Extensibility through Plugins

Nacos employs a plugin architecture for extensibility:

The plugin architecture allows for customization of various aspects of Nacos:

  • Authentication and authorization
  • Data encryption
  • Storage implementation
  • Control plane extensions
  • Tracing and monitoring

Sources: pom.xml620-623

Web Console

Nacos provides a web-based console for administration and management:

Console features:

  • Configuration creation, update, deletion
  • Service and instance management
  • Namespace management
  • Cluster node status
  • Configuration import/export
  • User and permission management

Sources: console/pom.xml26-29 console-ui/src/config.js1-155 console/src/main/java/com/alibaba/nacos/console/config/ConsoleModuleStateBuilder.java28-44

Deployment Models

Nacos supports different deployment models:

  1. Standalone Mode:

    • Single node deployment
    • Embedded Derby database
    • Suitable for development and testing
  2. Cluster Mode:

    • Multiple Nacos nodes for high availability
    • External database (MySQL) for data persistence
    • Built-in cluster management and data consistency mechanisms
  3. Multi-Cluster Mode:

    • Multiple Nacos clusters for cross-region deployment
    • Support for data synchronization between clusters

Sources: README.md40-71 distribution/pom.xml30-34

Summary

Nacos provides a comprehensive solution for service discovery, configuration management, and service governance in cloud-native environments. Its flexible architecture, rich feature set, and extensibility make it a powerful platform for microservices infrastructure.

The codebase is well-structured into modular components, with clear separation of concerns between the client SDK, server-side services, and administrative interface. The plugin system allows for customization and extension of various aspects of the system.

For more detailed information on specific components, refer to the respective wiki pages linked throughout this document.